import { APPID } from "@/config";

export default function getWxcode() {
  const params = new URLSearchParams(window.location.href.split("?")[1]);
  const code = params.get("code");
  if (!code) {
    const appid = APPID;
    const redirect_uri = encodeURIComponent(window.location.href);
    const href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`;
    window.location.href = href;
  } else {
    const app = getApp();
    app.globalData!.code = code;
  }
}
